<?php
include_once('admin/structures/tableEditors.php');
include_once('admin/structures/editorFields.php');

class adminCars extends simpleTableEditor
{
    //construct games object
    function adminCars()
    {
        global $lang;

        $this->simpleTableEditor(CARS_TABLE, 'cars', 'cars',  $lang['AdminEditCarsInfo'], true, true);
        $this->addColumn(new fieldId('c_id'));
        $this->addColumn(new fieldTitle($lang['CarModel'],'c_model','',50));
        $this->addColumn(new fieldText($lang['CarManufacturer'],'c_manufacturer','',50));
        $this->addColumn(new fieldLongText($lang['CarDescription'],'c_description','',5));
        $this->addColumn(new fieldText($lang['CarGameName'],'c_gameName','',50));
        $this->addColumn(new fieldTableQueryComboBox($lang['CarClass'],'c_class','','SELECT cl_id, cl_title FROM ' . CLASSES_TABLE . ' ORDER BY cl_title', 'cl_id', 'cl_title'));
        $logoThmb = new fieldDummy('c_logoThmb');
        $this->addColumn(new fieldImage($lang['Logo'],'c_logo','','cars',200,150, false, true, $logoThmb, 80, 60));
        $this->addColumn($logoThmb);
        $this->doStuff();

    }

    //Overwrite Selection Function
    protected function getSelectionOptions()
    {
        return array("query" =>
            'SELECT c_id, c_model, c_manufacturer FROM ' . CARS_TABLE . ' ORDER BY c_manufacturer',
            "id" => "c_id", "text" => "c_manufacturer", "minor" => "c_model");
    }
}


class adminCarClasses extends simpleTableEditor
{
    //construct games object
    function adminCarClasses()
    {
        global $lang;

        $this->simpleTableEditor(CLASSES_TABLE, 'carclasses', 'AdminEditCarClass',  $lang['AdminEditCarClassInfo'], true, true);
        $this->addColumn(new fieldId('cl_id'));
        $this->addColumn(new fieldTitle($lang['ClassTitle'],'cl_title','',50));
        $this->addColumn(new fieldTableQueryComboBox($lang['Game'],'cl_game','','SELECT g_id, g_name FROM ' . GAMES_TABLE . ' ORDER BY g_name ASC', 'g_id', 'g_name'));
        $this->addColumn(new fieldInfoOnly($lang['ClassCars'],'classcars','',
                'SELECT CONCAT(c_manufacturer, " ", c_model) as carname
                    FROM '. CARS_TABLE . ' WHERE c_class = %1$s
                    ORDER BY c_manufacturer, c_model', 'carname'));
        $this->doStuff();

    }

    //Overwrite Selection Function
    protected function getSelectionOptions()
    {
        return array("query" =>
            'SELECT cl_id, cl_title, g_name FROM ' . CLASSES_TABLE . ', ' . GAMES_TABLE . '
                WHERE g_id = cl_game ORDER BY cl_title',
            "id" => "cl_id", "text" => "cl_title", "minor" => "g_name");
    }

    //update cars
    protected function customPostDeleteActions()
    {
        global $db;
        $query = "UPDATE " . CARS_TABLE . " SET c_class = 0 WHERE c_class = " . $_POST['itemID'];
        $result = $db->sql_query($query);

    }
}
?>
